package com.shangxia.monomer.study.math.formula;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zhouya38158
 * @Package com.shangxia.monomer.study.math
 * @date 2021/7/22 9:19
 */
public class Lottery {

    public static void main(String[] args) {
        System.out.println(JSONObject.toJSONString(performLottery(10, 10)));
    }

    /**
     * 随机从 1-numNumbers 的数，不重复(numNumbers>=numbersToPick)
     *
     * @param numNumbers
     * @param numbersToPick
     * @return
     */
    public static Integer[] performLottery(int numNumbers, int numbersToPick) {
        List numbers = new ArrayList<Integer>();
        for (int i = 0; i < numNumbers; i++) {
            numbers.add(i + 1);
        }

        Collections.shuffle(numbers);
        return (Integer[]) numbers.subList(0, numbersToPick).toArray(new Integer[numbersToPick]);
    }
}
